package db_entity

import (
	"encoding/json"
	"time"
)

/**
 * @author 蔚蔚樱
 * @version V1.0
 * @date 2023/5/10 01:04
 * @author-Email micromicrohard@outlook.com
 * @blogURL https://blog.csdn.net/Micro_Micro_Hard
 * @description 新的表结构
 * */

type AlgoUTData struct {
	Id         int       `gorm:"column:id;primary_key;auto_increment" json:"id"`
	ClassName  string    `gorm:"column:class_name;not null" json:"class_name"`
	UTBody     string    `gorm:"column:ut_body;not null" json:"ut_body"`
	Creator    string    `gorm:"column:creator;not null;default:'jove'" json:"creator"`
	IsDeleted  int       `gorm:"column:id_delete;not null;default:0" json:"is_deleted"`
	CreateTime time.Time `gorm:"column:create_time;not null;default:CURRENT_TIMESTAMP" json:"create_time"`
	UpdateTime time.Time `gorm:"column:update_time;not null;default:CURRENT_TIMESTAMP" json:"update_time"`
}

func (entity *AlgoUTData) TableName() string {
	return "algo_ut_data"
}

func (entity *AlgoUTData) TransMap(mapValue map[interface{}]interface{}) *AlgoUTData {
	return &AlgoUTData{}
}

func (entity *AlgoUTData) TransUTDataEntity(utDataEntity *UTDataEntity) *AlgoUTData {
	if utDataEntity == nil {
		return &AlgoUTData{}
	}
	var (
		className  string
		input      string
		output     string
		inputDesc  string
		outputDesc string
		desc       string
	)
	if utDataEntity.ClassName != nil {
		className = *(utDataEntity).ClassName
	}
	if utDataEntity.Input != nil {
		input = *(utDataEntity).Input
	}
	if utDataEntity.OutputDesc != nil {
		output = *(utDataEntity).Output
	}
	if utDataEntity.InputDesc != nil {
		inputDesc = *(utDataEntity).InputDesc
	}
	if utDataEntity.OutputDesc != nil {
		outputDesc = *(utDataEntity).OutputDesc
	}
	if utDataEntity.ClassDescribe != nil {
		desc = *(utDataEntity).ClassDescribe
	}
	utBody := &UTBody{
		ClassName:    className,
		Input:        input,
		Output:       output,
		InputDesc:    inputDesc,
		OutputDesc:   outputDesc,
		TestCaseDesc: desc,
	}
	utBodyStr, _ := json.Marshal(utBody)
	return &AlgoUTData{
		ClassName: *utDataEntity.ClassName,
		UTBody:    string(utBodyStr),
		Creator:   "ljfirst",
	}
}

type UTBody struct {
	ClassName    string `json:"class_name"`     // 类名
	Input        string `json:"input"`          // 输入
	Output       string `json:"output"`         // 输出
	InputDesc    string `json:"input_desc"`     // 输入描述
	OutputDesc   string `json:"output_desc"`    // 输出描述
	TestCaseDesc string `json:"test_case_desc"` // 题目描述
}
